package com.example.web.topic;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.example.web.config.MQConfig;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Producer extends MQConfig {

	public static void main(String[] args) throws JMSException {
		// 创建会话
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		// 创建目的地
		Destination destination = session.createTopic(MQConfig.topicName);
		// 创建发布者
		MessageProducer producer = session.createProducer(destination);
		// 发布主题
		TextMessage message = session.createTextMessage("千里马常有，伯乐不常有！");
		producer.send(message);
		// 关闭连接
		connection.close();
	}

}
